package com.sf.admin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.sf.admin.mapper.UserMapper;
import com.sf.admin.model.po.User;
import com.sf.admin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	private UserMapper userMapper;

	@Override
	public User selectById(String id) {
		return userMapper.selectById(id);
	}

	@Override
	public List<User> selectAll(User user) {
		EntityWrapper<User> ew = new EntityWrapper();
		ew.like("user_name",user.getUserName());
		ew.like("phonenumber",user.getPhonenumber());
		List<User> users = userMapper.selectList(ew);
		return users;
	}

	@Override
	public int save(User user) {
		user.setUserId(IdWorker.getId());
		return userMapper.insert(user);
	}

	@Override
	public int delete(User user) {
		EntityWrapper<User> ew = new EntityWrapper<>();
		ew.eq("user_id",user.getUserId());
		return userMapper.delete(ew);
	}

	@Override
	public User getUserById(User user) {
		return userMapper.selectOne(user);
	}

	@Override
	public int update(User user) {
		EntityWrapper<User> ew = new EntityWrapper<>();
		ew.eq("user_id",user.getUserId());
		return userMapper.update(user,ew);
	}

}
